package com.concurrent.concurrentdemo.lock.zkLock;

public abstract class AbstractLock implements Lock{

    @Override
    public void lock() {
        if (tryLock()) {
            System.out.println("--------获取到了自定义Lock锁的资源--------");
        } else {
            // 没拿到锁则阻塞，等待拿锁
            waitLock();
            // 唤醒后再次递归获取lock
            lock();
        }
    }

    /**
     * 尝试获取锁，如果拿到了锁返回true，没有拿到则返回false
     */
    public abstract boolean tryLock();

    /**
     * 阻塞，等待获取锁
     */
    public abstract void waitLock();

}
